package com.yfq.springframework.aop.aspectj;

import com.yfq.springframework.aop.Pointcut;
import com.yfq.springframework.aop.PointcutAdvisor;
import org.aopalliance.aop.Advice;

/**
 * @author: yfq
 * @date: 2023/2/3 9:22
 * @description: 定义切点访问者，把Pointcut、Advice、切点表达式封装到一起，方便在xml中定义一个PointcutAdvisor
 */
public class AspectjExpressionPointcutAdvisor implements PointcutAdvisor {
    /**
     * 切点
     */
    private AspectJExpressionPointcut pointcut;
    /**
     * 切面方法
     */
    private Advice advice;
    /**
     * 切点表达式
     */
    private String expression;

    @Override
    public Advice getAdvice() {
        return advice;
    }

    @Override
    public Pointcut getPointcut() {
        if (pointcut == null) {
            pointcut = new AspectJExpressionPointcut(expression);
        }
        return pointcut;
    }

    public void setPointcut(AspectJExpressionPointcut pointcut) {
        this.pointcut = pointcut;
    }

    public void setAdvice(Advice advice) {
        this.advice = advice;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }
}
